package com.example.my.meila.view.adapter;

import android.content.Context;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.my.meila.R;
import com.example.my.meila.common.image.ImageLoader;
import com.example.my.meila.constast.Constast;
import com.example.my.meila.entity.Paihangbang;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhanghao on 2016/10/31.
 */
public class PaihangbangheadAdapter extends RecyclerView.Adapter<PaihangbangheadAdapter.MainViewholder> {

    private Context context;
    private List<Paihangbang.DataBean.FeatureShowBean> data;
    private PaihangbangTopheadAdapter adapter;

    public PaihangbangheadAdapter(Context context, List<Paihangbang.DataBean.FeatureShowBean> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public MainViewholder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.item_xrecyclerview_paihangbang, null);
        MainViewholder holder = new MainViewholder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MainViewholder holder, int position) {
        adapter = new PaihangbangTopheadAdapter(context, data.get(position).getProducts());
        LinearLayoutManager llm = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
        holder.rvPaihangbangRecyvlerviewTop.setLayoutManager(llm);
        holder.rvPaihangbangRecyvlerviewTop.setAdapter(adapter);
        ImageLoader.getInstance().display(context, Constast.PUBLIC_URL + data.get(position).getImg().getImg(), holder.ivPaihangbangXrecyclerviewImg);


    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class MainViewholder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_paihangbang_xrecyclerview_img)
        ImageView ivPaihangbangXrecyclerviewImg;
        @BindView(R.id.rv_paihangbang_recyvlerview_top)
        RecyclerView rvPaihangbangRecyvlerviewTop;

        public MainViewholder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);

        }
    }
}
